
//自定义组件
require(['garenjs/utils','garenjs/htmlui','garenjs/easyui',
	'datagrid-autoedit', "datagrid-lineEdit"],function(utils,garenUI,easyUI, autoEdit, lineEdit){
	
	easyUI.regFn({
	   name:'treegrid',
	   tag:'table',
	   onBeforeCreate:function(opts){
			//设置字段默认值
			$.each(opts.columns,function(i,column){
				$.each(column,function(j,field){
					if(field.rowspan || field.colspan || field.hidden) return;
					if(field.width == null) field.width = 100;
					if(field.align == null) field.align = 'center';
				});
			});
		},
		onCreate : function(jqObj, uiOpts) {// 回调函数
			var mygrid = jqObj;
			if (uiOpts.formDialog)
				autoEdit(jqObj, uiOpts);// 对话框编辑模式
			else if (uiOpts.lineEdit)
				lineEdit(jqObj, uiOpts);// 行内编辑模式
			if ($.isArray(uiOpts.toolbarEx)) {
				var toolbar = {
					eName : 'toolbar',
					addMode : "prepend",
					elements : uiOpts.toolbarEx
				};
				var panel = mygrid.treegrid("getPanel");
				panel.find('div.datagrid-toolbar').remove();// 删除旧的工具栏
				panel.createUI(toolbar);
				mygrid.datagrid('resize');// 重绘datagrid
			}
			return;// 退出
		}
	});
	/*
	 * Tree组件方法扩展
	 */
	$.extend($.fn.treegrid.methods,{
		
	});

	/*
	 * Tree组件属性扩展
	 */
	$.extend($.fn.treegrid.defaults,{
		fit:true
	});
	
});

